<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.common.DateUtil" %>
<%--获取流程待办和日程--%>
<%
    JSONObject jsonData = new JSONObject();
    User user = HrmUserVarify.getUser( request, response );
    int userid = user.getUID();
    int docount = getMyListDoing(userid);
    int reqcount = getMyListRequest(userid);
    int workcount = getWorkplan();
    jsonData.put( "docount", docount );
    jsonData.put( "reqcount", reqcount );
    jsonData.put( "workcount", workcount );
    out.print( jsonData.toJSONString() );
%>

<%!

    public static int getMyListDoing(int userid){
        RecordSet rs = new RecordSet();
        String sql = "select count(1) from (select  requestid,requestmark,createdate, createtime,creater, " +
                "creatertype, workflowid, requestname, requestnamenew, status,requestlevel," +
                "currentnodeid,viewtype,userid,receivedate,receivetime,isremark," +
                "nodeid,agentorbyagentid,agenttype,isprocessed ,systype,workflowtype," +
                "isbereject,takisremark,requestnamehtmlnew,viewDate,viewTime,lastFeedBackDate," +
                "lastFeedBackTime,needwfback,lastFeedBackOperator " +
                "from (select  t1.requestid,t1.requestmark,t1.createdate, " +
                "t1.createtime,t1.creater, t1.creatertype, t1.workflowid, " +
                "t1.requestname, t1.requestnamenew, t1.status,t1.requestlevel," +
                "t1.currentnodeid,t2.viewtype,t2.userid,t2.receivedate,t2.receivetime," +
                "t2.isremark,t2.nodeid,t2.agentorbyagentid,t2.agenttype,t2.isprocessed  " +
                ",t1.seclevel,'0' as systype,t2.workflowtype,t2.isbereject,t2.takisremark," +
                "t1.requestnamehtmlnew,t2.viewDate,t2.viewTime,t1.lastFeedBackDate," +
                "t1.lastFeedBackTime,t2.needwfback,t1.lastFeedBackOperator  " +
                "from workflow_requestbase t1,workflow_currentoperator t2,workflow_base " +
                "t3 where t1.requestid = t2.requestid and t1.workflowid=t3.id and " +
                "t2.userid in ("+userid+" ) and t2.usertype=0 and (isnull(t1.currentstatus,-1) " +
                "= -1 or (isnull(t1.currentstatus,-1)=0 and t1.creater in ("+userid+")))  " +
                " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='')  " +
                "and ((t2.isremark='0' and (t2.takisremark is null or t2.takisremark=0 )) " +
                "or t2.isremark in('1','5','8','9','7','11')) and t2.islasttimes=1 and " +
                "(isprocessing = '' or isprocessing is null)  and t3.isvalid in('1','3') " +
                " union (select distinct  requestid,'' as requestmark,createdate, " +
                "createtime,creatorid as creater, 0 as creatertype, workflowid, " +
                "requestname, requestname as requestnamenew, '' as status,requestlevel," +
                "-1 as currentnodeid,viewtype,userid,receivedate,receivetime,isremark,0 as nodeid, " +
                "-1 as agentorbyagentid,'0' as agenttype,'0' as isprocessed  ,'4' as secLevel," +
                "'1' as systype, sysid as workflowtype,'' as isbereject,0 as takisremark," +
                "'' as requestnamehtmlnew,'' as viewDate,'' as viewTime,'' as lastFeedBackDate," +
                "'' as lastFeedBackTime,'' as needwfback,0 as lastFeedBackOperator from ofs_todo_data " +
                " where 1=1   and userid in("+userid+") and islasttimes=1 and isremark in(0,8,9)  " +
                "and ofs_todo_data.pcurl is not null  and ofs_todo_data.pcurl <> '' ) ) t1 ) t1 ";
        rs.executeQuery(sql);
        rs.next();
        return Util.getIntValue(rs.getString(1));
    }

    public static int getMyListRequest(int userid){
        RecordSet rs = new RecordSet();
        String sql = "select count(1) from (select  requestid," +
                "requestmark,createdate, createtime,creater, creatertype, workflowid, " +
                "requestname, requestnamenew, status,requestlevel,currentnodeid,viewtype," +
                "userid,receivedate,receivetime,isremark,nodeid,agentorbyagentid,agenttype," +
                "isprocessed ,systype,workflowtype,isbereject,takisremark,requestnamehtmlnew," +
                "viewDate,viewTime,lastFeedBackDate,lastFeedBackTime,needwfback,lastFeedBackOperator " +
                "from (select  t1.requestid,t1.requestmark,t1.createdate, t1.createtime,t1.creater," +
                " t1.creatertype, t1.workflowid, t1.requestname, t1.requestnamenew, t1.status," +
                "t1.requestlevel,t1.currentnodeid,t2.viewtype,t2.userid,t2.receivedate,t2.receivetime," +
                "t2.isremark,t2.nodeid,t2.agentorbyagentid,t2.agenttype,t2.isprocessed  ,t1.seclevel," +
                "'0' as systype,t2.workflowtype,t2.isbereject,t2.takisremark,t1.requestnamehtmlnew," +
                "t2.viewDate,t2.viewTime,t1.lastFeedBackDate,t1.lastFeedBackTime,t2.needwfback," +
                "t1.lastFeedBackOperator  from workflow_requestbase t1,workflow_currentoperator t2," +
                "workflow_base t3 where t1.requestid = t2.requestid and t1.workflowid=t3.id and " +
                "t2.userid in ("+userid+") and t2.usertype=0 and (isnull(t1.currentstatus,-1) = -1 " +
                "or (isnull(t1.currentstatus,-1)=0 and t1.creater in ("+userid+")))   and (t1.deleted<>1 " +
                "or t1.deleted is null or t1.deleted='')  and t1.creater in ("+userid+") and t1.creatertype = 0 " +
                "and t1.creater = t2.userid  and ((t1.currentnodetype <> '3') " +
                "or (t2.isremark in('1','2','4','5','8','9','11') and t1.currentnodetype = '3' )) " +
                "and t2.islasttimes=1  and t3.isvalid in('1','3')  " +
                "union (select distinct  requestid,'' as requestmark,createdate, createtime," +
                "creatorid as creater, 0 as creatertype, workflowid, requestname, requestname as requestnamenew," +
                " '' as status,requestlevel,-1 as currentnodeid,viewtype,userid,receivedate,receivetime,isremark," +
                "0 as nodeid, -1 as agentorbyagentid,'0' as agenttype,'0' as isprocessed  ,'4' as secLevel," +
                "'1' as systype, sysid as workflowtype,'' as isbereject,0 as takisremark,'' as requestnamehtmlnew," +
                "'' as viewDate,'' as viewTime,'' as lastFeedBackDate,'' as lastFeedBackTime,'' as needwfback," +
                "0 as lastFeedBackOperator from ofs_todo_data  where 1=1   and creatorid in("+userid+") and creatorid=userid " +
                "and islasttimes=1  and isremark in(0,8,9)  and ofs_todo_data.pcurl is not null  and ofs_todo_data.pcurl <> '' ) ) t1" +
                " ) t1";
        rs.executeQuery(sql);
        rs.next();
        return Util.getIntValue(rs.getString(1));

    }

    public static int getWorkplan(){
        String curdate = DateUtil.getCurrentDate();
        RecordSet rs = new RecordSet();
        String sql = "select count(1) from WorkPlan workPlan, (SELECT workId,max(shareLevel) as shareLevel " +
                "from (  select workId,shareLevel from WorkPlanShareDetail where (objId = 1 and usertype = 1 " +
                "and shareType = '1' and securityLevel = 0 and securityLevelMax = 0)  " +
                "union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 1 and usertype = 1 and shareType = '6' and securityLevel = 0 " +
                "and securityLevelMax = 0)  union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 1 and usertype = 1 and shareType = '7' and securityLevel = 0 and " +
                "securityLevelMax = 0)  union all select workId,shareLevel from WorkPlanShareDetail " +
                " where (objId = 0 and usertype = 1 and shareType = '5' and  securityLevel<=30 and  " +
                "securityLevelMax>=30)  union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId in (0) and usertype=1 and shareType='2' and  securityLevel<=30 and  " +
                "securityLevelMax>=30)  union all select workId,shareLevel from WorkPlanShareDetail " +
                " where (objId in (0) and usertype=1 and shareType='3' and  securityLevel<=30 and  " +
                "securityLevelMax>=30)  union ALL SELECT workId,shareLevel from WorkPlanShareDetail " +
                "WHERE usertype = 1 AND shareType = '8' AND objId = '' AND ( joblevel = 0 " +
                "OR ( joblevel = 1 AND joblevelvalue in (0) ) OR ( joblevel = 2 AND joblevelvalue in (0)))" +
                " union all select workId,shareLevel from WorkPlanShareDetail  where (objId = 1 and " +
                "usertype=1 and shareType='4' and  securityLevel<=30 and  securityLevelMax>=30 " +
                "and 2>=rolelevel )  union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 2 and usertype=1 and shareType='4' and  securityLevel<=30 and  " +
                "securityLevelMax>=30 and 2>=rolelevel )  union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 3 and usertype=1 and shareType='4' and  securityLevel<=30 and  securityLevelMax>=30 " +
                "and 2>=rolelevel )  union all select workId,shareLevel from WorkPlanShareDetail " +
                " where (objId = 4 and usertype=1 and shareType='4' and  securityLevel<=30 and  " +
                "securityLevelMax>=30 and 2>=rolelevel )  union all select workId,shareLevel from WorkPlanShareDetail" +
                "  where (objId = 5 and usertype=1 and shareType='4' and  securityLevel<=30 and  securityLevelMax>=30 " +
                "and 2>=rolelevel )  union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 6 and usertype=1 and shareType='4' and  securityLevel<=30 and " +
                " securityLevelMax>=30 and 2>=rolelevel )  union all select workId,shareLevel " +
                "from WorkPlanShareDetail  where (objId = 7 and usertype=1 and shareType='4' and " +
                " securityLevel<=30 and  securityLevelMax>=30 and 2>=rolelevel )  " +
                "union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 8 and usertype=1 and shareType='4' and  securityLevel<=30 and  " +
                "securityLevelMax>=30 and 2>=rolelevel )  union all select workId,shareLevel " +
                "from WorkPlanShareDetail  where (objId = 9 and usertype=1 and shareType='4' and " +
                " securityLevel<=30 and  securityLevelMax>=30 and 2>=rolelevel )  " +
                "union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 10 and usertype=1 and shareType='4' and  securityLevel<=30 and " +
                " securityLevelMax>=30 and 2>=rolelevel )  union all select workId,shareLevel " +
                "from WorkPlanShareDetail  where (objId = 11 and usertype=1 and shareType='4' and " +
                " securityLevel<=30 and  securityLevelMax>=30 and 2>=rolelevel )  " +
                "union all select workId,shareLevel from WorkPlanShareDetail  where (objId = 12 " +
                "and usertype=1 and shareType='4' and  securityLevel<=30 and  securityLevelMax>=30 " +
                "and 2>=rolelevel )  union all select workId,shareLevel from WorkPlanShareDetail " +
                " where (objId = 13 and usertype=1 and shareType='4' and  securityLevel<=30 and " +
                " securityLevelMax>=30 and 2>=rolelevel )  union all select workId,shareLevel from " +
                "WorkPlanShareDetail  where (objId = 14 and usertype=1 and shareType='4' and  " +
                "securityLevel<=30 and  securityLevelMax>=30 and 2>=rolelevel )  " +
                "union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 15 and usertype=1 and shareType='4' and  securityLevel<=30 and  " +
                "securityLevelMax>=30 and 2>=rolelevel )  union all select workId,shareLevel " +
                "from WorkPlanShareDetail  where (objId = 16 and usertype=1 and shareType='4' and " +
                " securityLevel<=30 and  securityLevelMax>=30 and 2>=rolelevel )  " +
                "union all select workId,shareLevel from WorkPlanShareDetail  where (objId = 17 and usertype=1" +
                " and shareType='4' and  securityLevel<=30 and  securityLevelMax>=30 and 2>=rolelevel )  " +
                "union all select workId,shareLevel from WorkPlanShareDetail  where (objId = 18 and " +
                "usertype=1 and shareType='4' and  securityLevel<=30 and  securityLevelMax>=30 and " +
                "2>=rolelevel )  union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 19 and usertype=1 and shareType='4' and  securityLevel<=30 and  " +
                "securityLevelMax>=30 and 2>=rolelevel )  union all select workId,shareLevel from " +
                "WorkPlanShareDetail  where (objId = 20 and usertype=1 and shareType='4' and  " +
                "securityLevel<=30 and  securityLevelMax>=30 and 2>=rolelevel )  union all select " +
                "workId,shareLevel from WorkPlanShareDetail  where (objId = 21 and usertype=1 and " +
                "shareType='4' and  securityLevel<=30 and  securityLevelMax>=30 and 2>=rolelevel ) " +
                " union all select workId,shareLevel from WorkPlanShareDetail  " +
                "where (objId = 22 and usertype=1 and shareType='4' and  securityLevel<=30 and " +
                " securityLevelMax>=30 and 2>=rolelevel ) ) st1  group by st1.workId) workPlanShareDetail " +
                " where workPlan.ID = workPlanShareDetail.workID  and ( " +
                " (  (workplan.endDate > '"+curdate+"' or ( workplan.endDate = '"+curdate+"' and " +
                "workplan.endtime >= '00:00' ) )  and ( workplan.beginDate < '"+curdate+"' or ( workplan.beginDate = '"+curdate+"' " +
                "and workplan.beginTime <='23:59' ))  )  or (  (len(workplan.endDate)=0  " +
                "AND ( workplan.beginDate > '"+curdate+"' or ( workplan.beginDate = '"+curdate+"' " +
                "and workplan.beginTime >='00:00' )) ) )  )";
        rs.executeQuery(sql);
        rs.next();
        return Util.getIntValue(rs.getString(1));
    }
%>




